
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:paly_android/api/api.dart';
import 'package:paly_android/bean/article_data_entity.dart';
import 'package:paly_android/bean/banner_entity.dart';
import 'package:paly_android/net/dio_client.dart';

class BannerCubit extends Cubit<List<BannerEntity>> {
  BannerCubit() : super(List.empty());

  void getBannerData() {
    DioClient.instance.get(Api.BANNER, onSuccess: (List<BannerEntity> entity) {
      emit(entity);
    });
  }
}

class ArticleCubit extends Cubit<List<ArticleDataDatas>> {
  ArticleCubit() : super(List.empty(growable: true));

  void getArticle(int page, {bool isRefresh: true}) {
    DioClient.instance
        .get(Api.ARTICLE_LIST.replaceFirst("page", page.toString()),
            onSuccess: (ArticleDataEntity entity) {
      if (isRefresh) {
        state.clear();
      }
      emit(state..addAll(entity.datas));
    });
  }
}



